import request from 'utils/request'

/**
 * 获取文章列表数据
 * @returns Promise
 */
export const getArticles = (params) => {
  return request({
    method: 'GET',
    url: '/mp/articles',
    params
  })
}
/**
 * 获取文章详情
 * @returns Promise
 */
export const getArticleById = (target) => {
  return request({
    method: 'GET',
    url: `/mp/articles/${target}`
  })
}
/**
 * 修改文章
 * @param {*} data
 * @param {*} draft
 * @returns Promise
 */
export const updateArticle = (data, draft = false) => {
  return request.put(`/mp/articles/${data.id}?draft=${draft}`, data)
}
/**
 * 删除文章接口
 * @param {删除文章的id} target
 * @returns
 */
export const deleteArticle = (target) => {
  return request({
    url: `/mp/articles/${target}`,
    method: 'delete'
  })
}

/**
 * 发表文章
 * @param {*} data
 * @returns
 */
export const publishArticle = (data, draft = false) => {
  return request.post(`/mp/articles?draft=${draft}`, data)
}
